
import bpy

from 节点.全局控制.Node.节点和插座基类 import bl_节点基类

import Core.bl_UI配色 as UI配色
import engine.initLIB.load_dll as engineLib
import ctypes



engineLib.flexCAPI.f_创建标量关系运算节点.restype = ctypes.c_char
engineLib.flexCAPI.f_创建标量位运算节点.restype = ctypes.c_char








E_关系运算符_类型枚举 = [
	("TYPE_小于",		"<", "",	0),
	("TYPE_小于等于",	"<=", "",	1),
	("TYPE_大于",		">", "",	2),
	("TYPE_大于等于",	">=", "",	3),
	("TYPE_等于",		"==", "",	4),
	("TYPE_不等于",		"!=", "",	5),
]






E_位运算符_类型枚举 = [
	("TYPE_位与", "&", "", 0),
	("TYPE_位或", "|", "", 1),
	("TYPE_异或", "^", "", 2),
	("TYPE_位反", "~", "", 3),
	("TYPE_左移", "<<", "", 4),
	("TYPE_右移", ">>", "", 5),
]









def f_设置计算类型(self, context):
	data = list(str(self.m_运算类型))
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])









class C_Node_标量关系运算(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_标量关系运算'
	bl_label = '标量关系运算'
	bl_icon = 'FILE_IMAGE'

	m_运算类型 = bpy.props.EnumProperty(items=E_关系运算符_类型枚举, name="运算符", default="TYPE_小于", update=f_设置计算类型)
	def init(self, context):
		super(C_Node_标量关系运算, self).f_init(context)
		self.inputs.new('C_Socket_F32_Array1D', name='变量A')
		self.inputs.new('C_Socket_F32_Array1D', name='变量B')
		self.outputs.new('C_Socket_I8_Array1D', name='结果')
		self.f_toCPP(self.id_data)

	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建标量关系运算节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			f_设置计算类型(self, None)
		
	def draw_buttons(self, context, layout):
		layout.prop(self, "m_运算类型", text="运算类型")
		

class C_NODE_MENU_标量关系运算(bpy.types.Operator):
	bl_idname = 'node.create_node_scalar_relationship_operation'
	bl_label = '标量关系运算'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_标量关系运算', use_transform=True)
		return {'FINISHED'}
		











class C_Node_标量位运算(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_标量位运算'
	bl_label = '标量位运算'
	bl_icon = 'FILE_IMAGE'

	m_运算类型 = bpy.props.EnumProperty(items=E_位运算符_类型枚举, name="运算符", default="TYPE_位与", update=f_设置计算类型)
	def init(self, context):
		super(C_Node_标量位运算, self).f_init(context)
		self.inputs.new('C_Socket_I32_Array1D', name='变量A')
		self.inputs.new('C_Socket_I32_Array1D', name='变量B')
		self.outputs.new('C_Socket_I32_Array1D', name='结果')

		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色
		self.f_toCPP(self.id_data)

	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建标量位运算节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			f_设置计算类型(self, None)

	def draw_buttons(self, context, layout):
		layout.prop(self, "m_运算类型", text="运算类型")
		

class C_NODE_MENU_标量位运算(bpy.types.Operator):
	bl_idname = 'node.create_node_scalar_bit_operation'
	bl_label = '标量位运算'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_标量位运算', use_transform=True)
		return {'FINISHED'}














classes = (
	C_Node_标量关系运算,
	C_NODE_MENU_标量关系运算,

	C_Node_标量位运算,
	C_NODE_MENU_标量位运算,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)








